package com.zhangzhan.gulimallseckill.controller;

import com.zhangzhan.gulimallseckill.service.SeckillService;
import com.zhangzhan.gulimallseckill.tos.SeckillSkuRelationTo;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2024/7/4 18:33
 */

@RestController
public class SeckillController {

    @Autowired
    private SeckillService seckillService;

    /**
     * 首页查询所有当天可以秒杀的秒杀商品信息
     */
    @RequestMapping(value = "/getToDayCeckill", method = RequestMethod.GET)
    public List<SeckillSkuRelationTo> getToDayCeckill() {
        return seckillService.getToDayCeckill();
    }

    /**
     * 查询当前商品的秒杀信息
     */
    @RequestMapping(value = "/getSkuCeckill", method = RequestMethod.GET)
    public List<SeckillSkuRelationTo> getSkuCeckill(@RequestParam("skuId") Long skuId) {

        return seckillService.getSkuCeckill(skuId);
    }

    /**
     * 秒杀接口
     */
    @Valid
    @RequestMapping(value = "/seckill", method = RequestMethod.GET)
    public String seckill(@RequestParam("skuId") @NotNull Long skuId,
                          @RequestParam("killId") @NotNull Long killId,
                          @RequestParam("randomValue") @NotNull String randomValue,
                          @RequestParam("num") @NotNull Integer num) {
        return seckillService.seckill(skuId, killId, randomValue, num);
    }


}
